package br.unifor.bd.deadlock;

import java.util.Iterator;
import java.util.Vector;

class TimestampTransactionOrder {
	
	private Vector<String> timestampOrder = new Vector<String>();

	public void add(String transactionId) {
		Iterator<String> it = timestampOrder.iterator();
		boolean addTransaction = true;
		while (it.hasNext()) {
			if (it.next() == transactionId) {
				addTransaction = false;
			}
		}

		if (addTransaction) {
			timestampOrder.add(transactionId);
			System.out.println("[INFO] Adicionado marca de tempo para T"
					+ transactionId);
		}
	}

	public void remove(String transactionId) {
		Vector<String> tmp = new Vector<String>();
		Iterator<String> it = timestampOrder.iterator();
		while (it.hasNext()) {
			String t = it.next();
			if (t != transactionId) {
				tmp.add(t);
			}
		}
	}

	public String toString() {
		return timestampOrder.toString();
	}

}
